<?php 
session_start();
require('conf/runtime.conf.php');
require( DOM_PATH . 'Dom.init.php');

DomSql::init(MYSQL_HOST, MYSQL_USERNAME, MYSQL_PASSWORD, MYSQL_DATABASE);
DomAr::init();	


foreach( Brand::query()->commit() as $brand ) {
	$countries = CountryItem::idSetQuery('t.country')
		->join( Item::getDbTable(), 'i', ' i.id = t.item')
		->where('i.brand = '.(int)$brand->id)
		->groupBy('t.country')
		->commit()->toArray();
	$brand->countries->set( $countries );
	if( !$brand->save() ) {
		debug( $brand );
	}
}

echo 'done';

?>